package com.example.service.impl;

import com.example.common.Result;
import com.example.mapper.SupplyCompanyMapper;
import com.example.service.SupplyCompanyService;
import com.example.vo.SupplyCompanyVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class SupplyCompanyServiceImpl implements SupplyCompanyService {
    
    @Autowired
    private SupplyCompanyMapper supplyCompanyMapper;
    
    @Override
    public Result<List<SupplyCompanyVO>> getAllEnabledSupplyCompanies() {
        try {
            List<SupplyCompanyVO> supplyCompanies = supplyCompanyMapper.selectAllEnabled();
            return Result.success(supplyCompanies);
        } catch (Exception e) {
            log.error("查询所有启用的供货公司失败", e);
            return Result.error("查询供货公司列表失败");
        }
    }
    
    @Override
    public Result<SupplyCompanyVO> getSupplyCompanyById(Long id) {
        try {
            SupplyCompanyVO supplyCompanyVO = supplyCompanyMapper.selectVOById(id);
            if (supplyCompanyVO == null) {
                return Result.error("供货公司不存在");
            }
            return Result.success(supplyCompanyVO);
        } catch (Exception e) {
            log.error("查询供货公司失败，公司ID: {}", id, e);
            return Result.error("查询供货公司失败");
        }
    }
} 